﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Text;
using Microsoft.ApplicationBlocks.Data;

namespace AnyOffice.general.work_plan.manage
{
    public partial class Report_List : ModulePage
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {


            if (!this.Page.IsPostBack)
            { 
                string userId = (Request.QueryString["user_id"] == null) ? "" : Request.QueryString["user_id"].ToString();
                this.ViewState["UserId"] = userId;
                if (!SecurityManager.IsCanManage(userId))
                {
                    base.CloseConn();
                    Response.Write(base.ShowErrorNoNav("无权限"));
                    return;
                }

                // this.pnlDiary.Visible = false;
                // this.pnlMain.Visible = false;
                this.pnlResult.Visible = true;
                ArrayList list = new ArrayList();
                StringBuilder builder = new StringBuilder();
                builder.Append("SELECT  ");
                builder.Append("\t[Report_work].[ReportId], ");
                builder.Append("\t[Report_work].[Title], ");
                builder.Append("\t[Report_work].[Type], ");
                builder.Append("\t[Report_work].[ReportTime], ");
                builder.Append("\t[Report_work].[PlanID], ");
                builder.Append("\t[Report_work].[Year], ");
                builder.Append("\t[Report_work].[Month], ");
                builder.Append("\t[Users].[UserName], ");
                builder.Append("\t[Department].[DeptName] ");
                builder.Append("FROM ");
                builder.Append("\t[dbo].[Report_work], ");
                builder.Append("\t[dbo].[Users], ");
                builder.Append("\t[dbo].[Department] ");
                builder.Append("WHERE ");
                builder.Append("\t[Report_work].[UserId] = [Users].[UserId] ");
                builder.Append("\tAND [Users].[DeptId] = [Department].[DeptId] ");
                //    builder.Append("    AND Report_work.UserId = '" + this.ViewState["UserId"].ToString() + "' ");
                //if (this.ddYear.SelectedValue != "-1")
                //{
                //    builder.Append(" AND Report_work.Year = @Year ");
                //    list.Add(new object[] { "@Year", Convert.ToInt16(this.ddYear.SelectedValue) });
                //}
                //if (this.ddlMonth.SelectedValue != "-1")
                //{
                //    builder.Append(" AND Report_work.Month = @Month ");
                //    list.Add(new object[] { "@Month", Convert.ToInt16(this.ddlMonth.SelectedValue) });
                //}

                string plan_id = (Request.QueryString["plan_id"] == null) ? "" : Request.QueryString["plan_id"].ToString();
                if (plan_id != "")
                {
                    builder.Append(" AND Report_work.PlanID=@PlanID  ");
                    list.Add(new object[] { "@PlanID", plan_id });
                }
                builder.Append(" ORDER BY Report_work.ReportTime DESC");
                SqlParameter[] commandParameters = new SqlParameter[list.Count];
                for (int i = 0; i < list.Count; i++)
                {
                    object[] objArray4 = (object[])list[i];
                    commandParameters[i] = new SqlParameter(objArray4[0].ToString(), objArray4[1]);
                }
                DataTable table2 = SqlHelper.ExecuteDataset(base.Conn, CommandType.Text, builder.ToString(), commandParameters).Tables[0];
                if (table2.Rows.Count > 0)
                {
                    this.rptQuery.DataSource = table2;
                    this.rptQuery.DataBind();
                }
                else
                {
                    this.litMessage.Text = base.ShowMessage("无符合条件的月报");
                } 


            }
           
        }


        
    }
}